package com.zeng.createmd.restfulmodule.exception;

import com.zeng.nicecommon.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionResolver {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object handleExcption(Exception e) {
        log.error(e.getMessage(), e);
        return ResponseUtil.badRequest(e.getMessage());

    }

    @ResponseBody
    @ExceptionHandler(NullPointerException.class)
    public Object handleNull(Exception e) {
        log.error(e.getMessage(), e);
        return ResponseUtil.serviceError("服务器发生异常");
    }

}
